import { userList } from '../system/user/data'
import { createdToken } from './data/token'

export default [
  // 登录
  {
    url: '/system/auth/login',
    method: 'post',
    response: data => {
      let isUser = false
      let isLogin = false
      let userInfo = {}
      userList.forEach(function (item) {
        if (item.username === data.body.username) {
          isUser = true
          if (item.password === data.body.password) {
            isLogin = true
            userInfo = item
          }
        }
      })
      if (isUser) {
        if (isLogin) {
          const token = createdToken()
          return {
            code: 200,
            status: true,
            msg: '登录成功！',
            data: userInfo,
            accessToken: token.accessToken,
            refreshToken: token.refreshToken,
            expiresTime: token.expiresTime
          }
        } else {
          return {
            code: 300,
            status: false,
            msg: '密码错误！'
          }
        }
      } else {
        return {
          code: 300,
          status: false,
          msg: '用户名不存在！'
        }
      }
    }
  },
  // 登出
  {
    url: '/system/auth/logout',
    method: 'post',
    response: () => {
      return {
        code: 200,
        status: true,
        msg: '退出登录成功！'
      }
    }
  },
  // 用户重置密码
  {
    url: '/system/auth/user-reset',
    method: 'post',
    response: () => {
      return {
        code: 200,
        status: true,
        msg: '密码已重置！'
      }
    }
  }
]
